#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 13 14:25:25 2021

@author: Jessi
"""
import os
import yaml

FILE_DIR = os.path.dirname(os.path.dirname(__file__))
yaml._warnings_enabled['YAMLLoadWarning'] = False

def get_config_paths(name):
    "返回配置的路径。name = WeChat / TengMeeting / GUI / Other"
    with open(os.path.join(FILE_DIR, "config_paths.yaml"),
              encoding= "utf-8") as fp:
        d = yaml.load(fp)
    d = d[d["using label"]]
    if name:
        return d[name].format_map({"FILE_DIR": FILE_DIR})
    for k, v in d.items():
        d[k] = v.format_map({"FILE_DIR": FILE_DIR})
    return type("config paths", (object,), d)

class OtherConfig:
    "用于缓存非应用配置。只读。"
    def __init__(self):
        self.config = {}
        self.refresh()
    def refresh(self):
        with open(get_config_paths("Other"), encoding= "utf-8") as fp:
            self.config.update(yaml.load(fp))
    def __getitem__(self, key):
        return self.config[key]